
package com.health.controller;

import com.health.constant.ResultCodeConstant;
import com.health.pojo.domain.DoctorDO;
import com.health.pojo.domain.PatientDO;
import com.health.pojo.domain.UserDO;
import com.health.pojo.dto.*;
import com.health.pojo.query.QueryGroup;
import com.health.pojo.query.UserQuery;
import com.health.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.lang.Integer;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理
 *
 * @author WUYU_MIN
 * @date 2025-04-29 23:51:18
 */
@Tag(name = "用户管理")
@RequestMapping("user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户注册
     *
     * @param userDTO 用户信息
     * @return
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @Operation(summary = "用户注册")
    @ResponseBody
    public RestResult<Integer> registerUser(@RequestBody @Validated(CreateGroup.class) UserDTO userDTO) {
        Integer result = userService.registerUser(userDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    @RequestMapping(value = "/registerPatient", method = RequestMethod.POST)
    @Operation(summary = "患者注册")
    @ResponseBody
    public RestResult<Boolean> registerPatient(@RequestBody @Validated(CreateGroup.class) PatientDTO patientDTO) {
        Boolean result = userService.registerPatient(patientDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    @RequestMapping(value = "/registerDoctor", method = RequestMethod.POST)
    @Operation(summary = "医生注册")
    @ResponseBody
    public RestResult<Boolean> registerDoctor(@RequestBody @Validated(CreateGroup.class) DoctorDTO doctorDTO) {
        Boolean result = userService.registerDoctor(doctorDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 用户登录
     *
     * @param userDTO 用户信息
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @Operation(summary = "用户")
    @ResponseBody
    public RestResult<String> loginUser(@RequestBody @Validated(QueryGroup.class) UserDTO userDTO) {
        System.out.println("RestResult<String> loginUser");
        String result = userService.loginUser(userDTO);
        System.out.println(result);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 用户登出
     *
     * @param phone 用户电话信息
     * @return
     */
    @RequestMapping(value = "/logOff", method = RequestMethod.POST)
    @Operation(summary = "用户登出")
    @ResponseBody
    public RestResult<Boolean> logOff(String phone) {
        System.out.println("run RestResult<Boolean> logOff");
        Boolean result = userService.logOff(phone);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询用户在线状态
     *
     * @param userId 用户查询信息
     * @return
     */
    @RequestMapping(value = "/onlineStatus", method = RequestMethod.GET)
    @Operation(summary = "查询用户在线状态")
    public RestResult<Integer> getUserOnlineStatus(Integer userId) {
        System.out.println("id :" + userId);
        Integer result = userService.getUserOnlineStatus(userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除用户
     *
     * @param userDTO 用户信息
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "删除用户")
    @ResponseBody
    public RestResult<Boolean> deleteUser(@RequestBody @Validated(QueryGroup.class) UserDTO userDTO) {
        Boolean result = userService.deleteUser(userDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询个人信息
     *
     * @param userDTO 个人信息
     * @return 个人信息
     */
    @RequestMapping(value = "/selectUser", method = RequestMethod.POST)
    @Operation(summary = "查询用户")
    @ResponseBody
    public RestResult<UserInformation> selectUser(@RequestBody @Validated(QueryGroup.class) UserDTO userDTO) {
        System.out.println("selectUser");
        UserInformation result = userService.selectUser(userDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }


    /**
     * 查询患者
     *
     * @param name 患者姓名
     * @return 患者列表
     */
    @RequestMapping(value = "/queryPatientsByName", method = RequestMethod.GET)
    @Operation(summary = "查询患者")
    @ResponseBody
    public RestResult<List<PatientDO>> queryPatientsByName(@Validated String name) {
        List<PatientDO> result = userService.queryPatientsByName(name);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询医生
     *
     * @param name 医生姓名
     * @return 医生列表
     */
    @RequestMapping(value = "/queryDoctorsByName", method = RequestMethod.GET)
    @Operation(summary = "查询医生")
    @ResponseBody
    public RestResult<List<DoctorDO>> queryDoctorsByName(@Validated String name) {
        List<DoctorDO> result = userService.queryDoctorsByName(name);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }


    /**
     * 更新个人信息
     *
     * @param userDTO 个人信息
     * @return 更新结果     */
    @RequestMapping(value = "/updateUser", method = RequestMethod.PUT)
    @Operation(summary = "更新患者")
    @ResponseBody
    public RestResult<Boolean> updateUser(@RequestBody @Validated(QueryGroup.class) UserDTO userDTO) {
        System.out.println(userDTO);
        Boolean result = userService.updateUser(userDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }



    /**
     * 更新患者
     *
     * @param patientDTO 患者信息
     * @return 更新结果     */
    @RequestMapping(value = "/updatePatient", method = RequestMethod.PUT)
    @Operation(summary = "更新患者")
    @ResponseBody
    public RestResult<Boolean> updatePatient(@RequestBody @Validated(QueryGroup.class) PatientDTO patientDTO) {
        Boolean result = userService.updatePatient(patientDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 更新医生
     *
     * @param doctorDTO 医生信息
     * @return 更新结果
     */
    @RequestMapping(value = "/updateDoctor", method = RequestMethod.PUT)
    @Operation(summary = "更新医生")
    @ResponseBody
    public RestResult<Boolean> updateDoctor(@RequestBody @Validated(QueryGroup.class) DoctorDTO doctorDTO) {
        Boolean result = userService.updateDoctor(doctorDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }


}
